using Common.Commands.ContactCommands;
using Common.Enumerations;
using Common.Views;
using Core.Domain.Model;
using NUnit.Framework;
using Sanelib.Common.Extensions;
using Sanelib.Common.Helpers;
using Sanelib.DataView;

namespace IntegrationTests.Processors
{
    public class ContactProcessorTester : IntegrationTestBase
    {
        [Test]
        public void ShouldAddContact()
        {
            var command = new AddContact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.Se,
                Description = "With 1 year experiance in C# .net MVC",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);
            var repo = GetInstance<IViewRepository<ContactView>>();
            var contactView = repo.GetById(command.Id);

            Assert.AreEqual(contactView.Name, command.Name);
        }

        [Test]
        public void ShouldDeleteContact()
        {
            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "He is good man.",
                ImageData = ImageUtility.NoImageData
            };

            Persist(contact);

            var command = new DeleteContact(contact.Id);
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<ContactView>>();
            var contactView = repo.GetById(command.Id);

            Assert.IsNull(contactView);
        }

        [Test, ExpectedException]
        public void ShouldNotAddSameNameContact()
        {
            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "With 1 yeat experiance in c#. net MVC",
                ImageData = ImageUtility.NoImageData
            };

            Persist(contact);

            var command = new AddContact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mrs,
                LastName = "Shailesh",
                FirstName = "Balar",
                Email = "kdl@gmail.com",
                Phone = "9824873493",
                Mobile = "8866766756",
                CompanyName = "Sailfin Tech",
                Designation = Designation.Md,
                Description = "With 10+ year experiance in C# .net MVC",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);
        }

        [Test]
        public void ShouldUpdateContact()
        {
            var contact = new Contact
            {
                Id = GuidComb.New(),
                Name = "NikunjBBalar",
                NameTitle = NameTitle.Mr,
                LastName = "Nikunj",
                FirstName = "Balar",
                Email = "niksunjbbalar@gmail.com",
                Phone = "9099791517",
                Mobile = "9099791517",
                CompanyName = "Sanelib Software Solutions",
                Designation = Designation.De,
                Description = "With 1 yeat experiance in c#. net MVC",
                ImageData = ImageUtility.NoImageData
            };

            Persist(contact);

            var command = new UpdateContact
            {
                Id = contact.Id,
                Name = "SunnyRajwadi",
                NameTitle = NameTitle.Mr,
                LastName = "Sunny",
                FirstName = "Rajwadi",
                Email = "sunny@sanelib.com",
                Phone = "8734002403",
                Mobile = "8734002403",
                CompanyName = "Sanelib Software solutions",
                Designation = Designation.Md,
                Description = "UpdatedDescription",
                ImageData = ImageUtility.NoImageData
            };
            ProcessCommand(command);

            var repo = GetInstance<IViewRepository<ContactView>>();
            var contactView = repo.GetById(command.Id);

            Assert.AreEqual(contactView.Id, contact.Id);
            Assert.AreNotEqual(contactView.Designation, contact.Designation);
        }
    }
}